<?php
$this->headTitle('Post edit');
$this->placeholder('content_title')->set('Write Your Post');
$this->placeholder('body_onload')->set('document.formPostEdit.post_title.focus();');

/*
$dojoConfig = Kbs::initConfig('Dojo');
if ($dojoConfig->enable) {
    $this->headScript()->setAllowArbitraryAttributes($dojoConfig->allowArbitraryAttributes);
    $this->headScript()->appendFile($dojoConfig->path . '/dojo/dojo.js', 'text/javascript', array('djConfig' => 'parseOnLoad: true, isDebug: false'));
    $this->headLink()->appendStylesheet($dojoConfig->path . '/dojo/resources/dojo.css');
    $this->headLink()->appendStylesheet($dojoConfig->path . '/dijit/themes/tundra/tundra.css');
    $this->placeholder('body_theme')->set('tundra');
}

$this->headScript()->captureStart();
echo 'dojo.require("dojo.parser");', "\n";
echo 'dojo.require("dijit.Editor");', "\n";
$this->headScript()->captureEnd();
*/

if (isset($this->post)) {
    $this->postId           = $this->post->postId;
    $this->postCategoryId   = $this->post->postCategoryId;
    $this->postUrlTitle     = $this->post->postUrlTitle;
    $this->postCreatedAt    = $this->post->postCreatedAt;
    $this->postUpdatedAt    = $this->post->postUpdatedAt;

    if (!empty($this->details)) {
        foreach ($this->details as $detail) {
            $localeId = $detail->detailLocaleId;
            $detailId[$localeId] = $detail->detailId;
            $detailTitle[$localeId] = $detail->detailTitle;
            $detailContent[$localeId] = $detail->detailContent;
        }
    }
}
?>
<div>
    <form name="formPostEdit" id="formPostEdit" method="post" action="<?php echo $this->U('post', 'save'); ?>">
        <div>
            <label>Title in url (option): </label>
            <?php echo $this->formText('postUrlTitle', $this->postUrlTitle, array('maxlength' => 255, 'size' => '70')); ?>

        </div>

        <div class="cl" style="height:15px;">&nbsp;</div>

        <div>
            <?php echo $this->formSelect('postCategoryId', $this->postCategoryId, null, $this->categoryOptions); ?>
        </div>

        <div class="cl" style="height:20px;">&nbsp;</div>

        <?php

        //var_dump($locales);
        if (!empty($this->locales)) {
            foreach ($this->locales as $locale) {
                $id = isset($detailId[$locale->localeId]) ? $detailId[$locale->localeId] : '';
                $title = isset($detailTitle[$locale->localeId]) ? $detailTitle[$locale->localeId] : '';
        ?>
                <?php echo $this->formHidden('detailId[' . $locale->localeId . ']', $id); ?>

                <div class="fl">
                    <label>Title (<?php echo $locale->localeTitle; ?>) : </label><br />
                    <?php echo $this->formText('detailTitle['.$locale->localeId.']', $title, array('maxlength' => 255, 'size' => '70')); ?>
                </div>
                <div class="fl" style="width:15px;">&nbsp;</div>
        <?php
            }
        }
        ?>

        <div class="cl" style="height:20px;">&nbsp;</div>

        <?php
        if (!empty($this->locales)) {
            foreach ($this->locales as $locale) {
                $content = isset($detailContent[$locale->localeId]) ? $detailContent[$locale->localeId] : '';
        ?>
                <div class="fl">
                    <label>Content (<?php echo $locale->localeTitle; ?>) : </label><br />
                    <?php echo $this->fckeditor('detailContent[' . $locale->localeId . ']', $content, '550', '800'); ?>
                </div>
        <?php
            }
        }
        ?>

        <div class="cl" style="height:20px;">&nbsp;</div>

        <?php echo $this->formHidden('postId', $this->postId); ?>
        <?php echo $this->formHidden('postAuthorId', 1); ?>
        <?php echo $this->formHidden('postCreatedAt', $this->postCreatedAt); ?>
        <?php echo $this->formHidden('postUpdatedAt', ''); ?>

        <div>
            <?php echo $this->formSubmit('Save', 'Save'); ?>
        </div>

    </form>
</div>